﻿using System;
using UnityEngine;
using UnityEngine.UI;

namespace Valve.VR.InteractionSystem
{
	// Token: 0x02000659 RID: 1625
	public class TeleportPoint : TeleportMarkerBase
	{
		// Token: 0x170004F9 RID: 1273
		// (get) Token: 0x06002963 RID: 10595 RVA: 0x000F0E48 File Offset: 0x000EF048
		public override bool showReticle
		{
			get
			{
				return false;
			}
		}

		// Token: 0x06002964 RID: 10596 RVA: 0x000F0E4C File Offset: 0x000EF04C
		private void Awake()
		{
			this.GetRelevantComponents();
			this.animation = base.GetComponent<Animation>();
			this.tintColorID = Shader.PropertyToID("_TintColor");
			this.moveLocationIcon.gameObject.SetActive(false);
			this.switchSceneIcon.gameObject.SetActive(false);
			this.lockedIcon.gameObject.SetActive(false);
			this.UpdateVisuals();
		}

		// Token: 0x06002965 RID: 10597 RVA: 0x000F0EB4 File Offset: 0x000EF0B4
		private void Start()
		{
			this.player = Player.instance;
		}

		// Token: 0x06002966 RID: 10598 RVA: 0x000F0EC4 File Offset: 0x000EF0C4
		private void Update()
		{
			if (Application.isPlaying)
			{
				this.lookAtPosition.x = this.player.hmdTransform.position.x;
				this.lookAtPosition.y = this.lookAtJointTransform.position.y;
				this.lookAtPosition.z = this.player.hmdTransform.position.z;
				this.lookAtJointTransform.LookAt(this.lookAtPosition);
			}
		}

		// Token: 0x06002967 RID: 10599 RVA: 0x000F0F50 File Offset: 0x000EF150
		public override bool ShouldActivate(Vector3 playerPosition)
		{
			return Vector3.Distance(base.transform.position, playerPosition) > 1f;
		}

		// Token: 0x06002968 RID: 10600 RVA: 0x000F0F6C File Offset: 0x000EF16C
		public override bool ShouldMovePlayer()
		{
			return true;
		}

		// Token: 0x06002969 RID: 10601 RVA: 0x000F0F70 File Offset: 0x000EF170
		public override void Highlight(bool highlight)
		{
			if (!this.locked)
			{
				if (highlight)
				{
					this.SetMeshMaterials(Teleport.instance.pointHighlightedMaterial, this.titleHighlightedColor);
				}
				else
				{
					this.SetMeshMaterials(Teleport.instance.pointVisibleMaterial, this.titleVisibleColor);
				}
			}
			if (highlight)
			{
				this.pointIcon.gameObject.SetActive(true);
				this.animation.Play();
			}
			else
			{
				this.pointIcon.gameObject.SetActive(false);
				this.animation.Stop();
			}
		}

		// Token: 0x0600296A RID: 10602 RVA: 0x000F1004 File Offset: 0x000EF204
		public override void UpdateVisuals()
		{
			if (!this.gotReleventComponents)
			{
				return;
			}
			if (this.locked)
			{
				this.SetMeshMaterials(Teleport.instance.pointLockedMaterial, this.titleLockedColor);
				this.pointIcon = this.lockedIcon;
				this.animation.clip = this.animation.GetClip("locked_idle");
			}
			else
			{
				this.SetMeshMaterials(Teleport.instance.pointVisibleMaterial, this.titleVisibleColor);
				TeleportPoint.TeleportPointType teleportPointType = this.teleportType;
				if (teleportPointType != TeleportPoint.TeleportPointType.MoveToLocation)
				{
					if (teleportPointType == TeleportPoint.TeleportPointType.SwitchToNewScene)
					{
						this.pointIcon = this.switchSceneIcon;
						this.animation.clip = this.animation.GetClip("switch_scenes_idle");
					}
				}
				else
				{
					this.pointIcon = this.moveLocationIcon;
					this.animation.clip = this.animation.GetClip("move_location_idle");
				}
			}
			this.titleText.text = this.title;
		}

		// Token: 0x0600296B RID: 10603 RVA: 0x000F1104 File Offset: 0x000EF304
		public override void SetAlpha(float tintAlpha, float alphaPercent)
		{
			this.tintColor = this.markerMesh.material.GetColor(this.tintColorID);
			this.tintColor.a = tintAlpha;
			this.markerMesh.material.SetColor(this.tintColorID, this.tintColor);
			this.switchSceneIcon.material.SetColor(this.tintColorID, this.tintColor);
			this.moveLocationIcon.material.SetColor(this.tintColorID, this.tintColor);
			this.lockedIcon.material.SetColor(this.tintColorID, this.tintColor);
			this.titleColor.a = this.fullTitleAlpha * alphaPercent;
			this.titleText.color = this.titleColor;
		}

		// Token: 0x0600296C RID: 10604 RVA: 0x000F11D0 File Offset: 0x000EF3D0
		public void SetMeshMaterials(Material material, Color textColor)
		{
			this.markerMesh.material = material;
			this.switchSceneIcon.material = material;
			this.moveLocationIcon.material = material;
			this.lockedIcon.material = material;
			this.titleColor = textColor;
			this.fullTitleAlpha = textColor.a;
			this.titleText.color = this.titleColor;
		}

		// Token: 0x0600296D RID: 10605 RVA: 0x000F1234 File Offset: 0x000EF434
		public void TeleportToScene()
		{
			if (!string.IsNullOrEmpty(this.switchToScene))
			{
				GlobalData.Debug_Log("TeleportPoint: Hook up your level loading logic to switch to new scene: " + this.switchToScene);
			}
			else
			{
				GlobalData.Debug_LogError("TeleportPoint: Invalid scene name to switch to: " + this.switchToScene);
			}
		}

		// Token: 0x0600296E RID: 10606 RVA: 0x000F1280 File Offset: 0x000EF480
		public void GetRelevantComponents()
		{
			this.markerMesh = base.transform.Find("teleport_marker_mesh").GetComponent<MeshRenderer>();
			this.switchSceneIcon = base.transform.Find("teleport_marker_lookat_joint/teleport_marker_icons/switch_scenes_icon").GetComponent<MeshRenderer>();
			this.moveLocationIcon = base.transform.Find("teleport_marker_lookat_joint/teleport_marker_icons/move_location_icon").GetComponent<MeshRenderer>();
			this.lockedIcon = base.transform.Find("teleport_marker_lookat_joint/teleport_marker_icons/locked_icon").GetComponent<MeshRenderer>();
			this.lookAtJointTransform = base.transform.Find("teleport_marker_lookat_joint");
			this.titleText = base.transform.Find("teleport_marker_lookat_joint/teleport_marker_canvas/teleport_marker_canvas_text").GetComponent<Text>();
			this.gotReleventComponents = true;
		}

		// Token: 0x0600296F RID: 10607 RVA: 0x000F1334 File Offset: 0x000EF534
		public void ReleaseRelevantComponents()
		{
			this.markerMesh = null;
			this.switchSceneIcon = null;
			this.moveLocationIcon = null;
			this.lockedIcon = null;
			this.lookAtJointTransform = null;
			this.titleText = null;
		}

		// Token: 0x06002970 RID: 10608 RVA: 0x000F1360 File Offset: 0x000EF560
		public void UpdateVisualsInEditor()
		{
			if (Application.isPlaying)
			{
				return;
			}
			this.GetRelevantComponents();
			if (this.locked)
			{
				this.lockedIcon.gameObject.SetActive(true);
				this.moveLocationIcon.gameObject.SetActive(false);
				this.switchSceneIcon.gameObject.SetActive(false);
				this.markerMesh.sharedMaterial = Teleport.instance.pointLockedMaterial;
				this.lockedIcon.sharedMaterial = Teleport.instance.pointLockedMaterial;
				this.titleText.color = this.titleLockedColor;
			}
			else
			{
				this.lockedIcon.gameObject.SetActive(false);
				this.markerMesh.sharedMaterial = Teleport.instance.pointVisibleMaterial;
				this.switchSceneIcon.sharedMaterial = Teleport.instance.pointVisibleMaterial;
				this.moveLocationIcon.sharedMaterial = Teleport.instance.pointVisibleMaterial;
				this.titleText.color = this.titleVisibleColor;
				TeleportPoint.TeleportPointType teleportPointType = this.teleportType;
				if (teleportPointType != TeleportPoint.TeleportPointType.MoveToLocation)
				{
					if (teleportPointType == TeleportPoint.TeleportPointType.SwitchToNewScene)
					{
						this.moveLocationIcon.gameObject.SetActive(false);
						this.switchSceneIcon.gameObject.SetActive(true);
					}
				}
				else
				{
					this.moveLocationIcon.gameObject.SetActive(true);
					this.switchSceneIcon.gameObject.SetActive(false);
				}
			}
			this.titleText.text = this.title;
			this.ReleaseRelevantComponents();
		}

		// Token: 0x0400299D RID: 10653
		public TeleportPoint.TeleportPointType teleportType;

		// Token: 0x0400299E RID: 10654
		public string title;

		// Token: 0x0400299F RID: 10655
		public string switchToScene;

		// Token: 0x040029A0 RID: 10656
		public Color titleVisibleColor;

		// Token: 0x040029A1 RID: 10657
		public Color titleHighlightedColor;

		// Token: 0x040029A2 RID: 10658
		public Color titleLockedColor;

		// Token: 0x040029A3 RID: 10659
		public bool playerSpawnPoint;

		// Token: 0x040029A4 RID: 10660
		private bool gotReleventComponents;

		// Token: 0x040029A5 RID: 10661
		private MeshRenderer markerMesh;

		// Token: 0x040029A6 RID: 10662
		private MeshRenderer switchSceneIcon;

		// Token: 0x040029A7 RID: 10663
		private MeshRenderer moveLocationIcon;

		// Token: 0x040029A8 RID: 10664
		private MeshRenderer lockedIcon;

		// Token: 0x040029A9 RID: 10665
		private MeshRenderer pointIcon;

		// Token: 0x040029AA RID: 10666
		private Transform lookAtJointTransform;

		// Token: 0x040029AB RID: 10667
		private Animation animation;

		// Token: 0x040029AC RID: 10668
		private Text titleText;

		// Token: 0x040029AD RID: 10669
		private Player player;

		// Token: 0x040029AE RID: 10670
		private Vector3 lookAtPosition = Vector3.zero;

		// Token: 0x040029AF RID: 10671
		private int tintColorID;

		// Token: 0x040029B0 RID: 10672
		private Color tintColor = Color.clear;

		// Token: 0x040029B1 RID: 10673
		private Color titleColor = Color.clear;

		// Token: 0x040029B2 RID: 10674
		private float fullTitleAlpha;

		// Token: 0x040029B3 RID: 10675
		private const string switchSceneAnimation = "switch_scenes_idle";

		// Token: 0x040029B4 RID: 10676
		private const string moveLocationAnimation = "move_location_idle";

		// Token: 0x040029B5 RID: 10677
		private const string lockedAnimation = "locked_idle";

		// Token: 0x0200065A RID: 1626
		public enum TeleportPointType
		{
			// Token: 0x040029B7 RID: 10679
			MoveToLocation,
			// Token: 0x040029B8 RID: 10680
			SwitchToNewScene
		}
	}
}
